from django.shortcuts import render

# Create your views here.
from django.views import View
from django.http import HttpResponse

from my_users.models import tb_class, tb_stu


class ClzTest(View):

    def post(self, request):
        clz1 = request.POST.get('clz_name')
        clz2 = tb_class()
        clz2.clz_name = clz1
        clz2.save()
        print(clz2)
        return HttpResponse('ok')


class StuTest(View):
    def post(self, request):
        name = request.POST.get('name')
        age = request.POST.get('age')
        clz = request.POST.get('clz')

        # print(name,age,clz)
        cla = tb_class.objects.filter(clz_name=clz)

        print(cla)
        stu1 = tb_stu()

        stu1.stu_name = name
        stu1.stu_age = age
        stu1.clz = cla[0]
        stu1.save()
        return HttpResponse('ok')


class showStu(View):
    def get(self, request):
        id = request.GET.get('clz')
        clz_name = tb_stu.objects.filter(clz=id)
        str01 = []
        for i in clz_name:
            str01.append(i)
        print(str01)
        return HttpResponse('%s' % str01)
